﻿using UnityEngine;
using System.Collections;
//旋转的实体类
[System.Serializable]//序列化
public class RotData
{
    public  float delay;
    public float angle;

    public RotData(float delay, float angle)
    {
        this.delay = delay;
        this.angle = angle;
    }
}
public class MoveCaer : MonoBehaviour {
    public float moveSpeed = 1;
    public float rotespeed = 10;
    public float rotDelay = 0;//开始计算旋转的延迟
    public RotData[] roArr = {new RotData(2,20),new RotData(2,-20)};
    int index = 0;
	// Use this for initialization
	void Start () {
        StartCoroutine(RotCoroutine());
	}
	
	// Update is called once per frame
	void Update () {
        transform.Translate(Vector3.down * moveSpeed * Time.deltaTime);
	}

    IEnumerator RotCoroutine()
    {
        yield return new WaitForSeconds(rotDelay);
        while (index<roArr.Length)
        {
            yield return new WaitForSeconds(roArr[index].delay);
            float angle = roArr[index].angle;
            float sign = Mathf.Sign(angle);
            while (true)
            {
                yield return 0;
                angle -= sign * rotespeed*Time.deltaTime;
                transform.Rotate(Vector3.forward, rotespeed*sign * Time.deltaTime);
                if (sign * angle < 0)
                {
                    break;
                }
            }
            index++;
        }
        
    }
}
